{% extends "base.html" %}

{% block title %}超市申请管理 - 妙趣拾光锦盒管理系统{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12 d-flex justify-content-between align-items-center">
        <h2 class="mb-0"><i class="fas fa-clipboard-list me-2"></i>超市申请管理</h2>
        <a href="{{ url_for('supermarket.list') }}" class="btn btn-outline-primary">
            <i class="fas fa-store me-1"></i>返回超市列表
        </a>
    </div>
</div>

<!-- 状态统计 -->
<div class="row mb-4">
    <div class="col-md-4">
        <div class="card border-left-primary shadow-sm h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">待审核申请</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ pending_count }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-hourglass-half fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card border-left-success shadow-sm h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-success text-uppercase mb-1">已批准申请</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">
                            {{ applications|selectattr('status', 'equalto', 'approved')|list|length }}
                        </div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-check-circle fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card border-left-danger shadow-sm h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-danger text-uppercase mb-1">已拒绝申请</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">
                            {{ applications|selectattr('status', 'equalto', 'rejected')|list|length }}
                        </div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-times-circle fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 筛选器 -->
<div class="card mb-4 shadow-sm">
    <div class="card-header bg-light">
        <h5 class="mb-0"><i class="fas fa-filter me-2"></i>筛选条件</h5>
    </div>
    <div class="card-body">
        <form method="GET" action="{{ url_for('supermarket.applications') }}">
            <div class="row">
                <div class="col-md-6 mb-2">
                    <label for="status" class="form-label">申请状态</label>
                    <select class="form-select" id="status" name="status">
                        <option value="">全部</option>
                        <option value="pending" {% if status_filter == 'pending' %}selected{% endif %}>待审核</option>
                        <option value="approved" {% if status_filter == 'approved' %}selected{% endif %}>已批准</option>
                        <option value="rejected" {% if status_filter == 'rejected' %}selected{% endif %}>已拒绝</option>
                    </select>
                </div>
                <div class="col-md-6 mb-2">
                    <label for="keyword" class="form-label">关键词（超市名称/地址/联系人）</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="{{ keyword }}">
                </div>
            </div>
            <div class="d-flex justify-content-end mt-3">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-search me-1"></i>查询
                </button>
                <a href="{{ url_for('supermarket.applications') }}" class="btn btn-secondary ms-2">
                    <i class="fas fa-redo me-1"></i>重置
                </a>
            </div>
        </form>
    </div>
</div>

<!-- 申请列表 -->
<div class="card shadow-sm">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th scope="col">#</th>
                        <th scope="col">超市名称</th>
                        <th scope="col">地址</th>
                        <th scope="col">联系人</th>
                        <th scope="col">联系电话</th>
                        <th scope="col">申请时间</th>
                        <th scope="col">状态</th>
                        <th scope="col">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for app in applications %}
                    <tr>
                        <td>{{ app.id }}</td>
                        <td>{{ app.name }}</td>
                        <td>{{ app.address }}</td>
                        <td>{{ app.contact_name }}</td>
                        <td>{{ app.contact_phone }}</td>
                        <td>{{ app.apply_time.strftime('%Y-%m-%d %H:%M') }}</td>
                        <td>
                            {% if app.status == 'pending' %}
                            <span class="badge bg-warning text-dark">待审核</span>
                            {% elif app.status == 'approved' %}
                            <span class="badge bg-success">已批准</span>
                            {% elif app.status == 'rejected' %}
                            <span class="badge bg-danger">已拒绝</span>
                            {% endif %}
                        </td>
                        <td>
                            <a href="{{ url_for('supermarket.application_detail', app_id=app.id) }}" class="btn btn-sm btn-primary">
                                <i class="fas fa-search me-1"></i>详情
                            </a>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="8" class="text-center py-4">
                            <div class="text-muted">
                                <i class="fas fa-clipboard-list fa-3x mb-3"></i>
                                <p>暂无申请数据</p>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    // 如果有未处理的申请，标题闪烁提醒
    $(document).ready(function() {
        const pendingCount = {{ pending_count }};
        if (pendingCount > 0) {
            let title = document.title;
            let isOriginal = true;
            
            setInterval(function() {
                document.title = isOriginal ? 
                    `(${pendingCount}条待审核) ${title}` : 
                    title;
                isOriginal = !isOriginal;
            }, 1000);
        }
    });
</script>
{% endblock %} 